from pages.base_page import BasePage
from pages.cart_page import CartPage
from pages.elements import Elements
from pages.order_page import OrderPage

'''
商品详情页
'''
class ProductDetailPage(BasePage):

    #http://127.0.0.1:9000/#/details?id=86

    add_to_cart_ele = {'type': 'id', 'value': 'button-cart'}
    cart_button_ele = {'type': 'id', 'value': 'cart-total'}
    view_cart_ele = {'type': 'link', 'value': 'View Cart'}

    def add_to_cart(self):
        self.click_element(self.add_to_cart_ele['value'], by=self.add_to_cart_ele['type'])

    '''
    加入购物车
    '''
    def go_to_cart(self):
        self.click_element(self.cart_button_ele['value'], by=self.cart_button_ele['type'])
        self.click_element(self.view_cart_ele['value'], by=self.view_cart_ele['type'])
        return CartPage()
    '''
    下架，如果这个物品是自己发布的
    '''
    def xiajia(self):
        self.click_element(self.cart_button_ele['value'], by=self.cart_button_ele['type'])
        self.click_element(self.view_cart_ele['value'], by=self.view_cart_ele['type'])
        return CartPage()

    '''
    收藏
    '''
    def star_product(self):
        self.sleep()
        star_btn = self.find_element(Elements.SHOUCANG_BTN)
        self.click_element(Elements.SHOUCANG_BTN)
        return star_btn.text
    '''
    获取收藏按钮的名字
    '''
    def star_btn_name(self):
        self.sleep(2)
        star_btn = self.find_element(Elements.SHOUCANG_BTN)
        return star_btn.text
    '''
    立即购买
    '''
    def to_buy(self):
        self.sleep()
        self.click_element(Elements.BUY_BTN)
        return OrderPage()
